<template>
  <div>
    <el-dialog
      :visible.sync="dialog.add"
      :close-on-click-modal="false"
      title="添加"
      width="80%"
      append-to-body
      @closed="dialogClosed('addForm')"
    >
      <el-form ref="addForm" :model="form" label-width="120px" :rules="validateRules">
        <el-row>
          <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="8">
	<el-form-item label="角色名称" prop="roleTitle"><el-input v-model="form.roleTitle" placeholder="请输入角色名称" disabled clearable />
              <el-button
                type="text"
                size="small"
                @click="showJoinSearch({
                searchDialog: 'RoleMain'
              })"
              >选择角色名称</el-button>
</el-form-item>
	</el-col>
<el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="8">
	<el-form-item label="商品标题" prop="goodsTitle"><el-input v-model="form.goodsTitle" placeholder="请输入商品标题" disabled clearable />
              <el-button
                type="text"
                size="small"
                @click="showJoinSearch({
                searchDialog: 'GoodsInfoMain'
              })"
              >选择商品标题</el-button>
</el-form-item>
	</el-col>
<el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="8">
	<el-form-item label="商品图片" prop="goodsPicUrl"><UploadImage
                v-if="dialog.add"
                action="actionUrl"
                formProp="goodsPicUrl"
                :fileList="[]"
                @imgUploadSuccess="imgUploadSuccess"
                @imgRemoveSuccess="imgRemoveSuccess"
              />
</el-form-item>
	</el-col>
<el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24">
	<el-form-item label="售卖标题" prop="skuTitle">
	<el-input type="textarea" v-model="form.skuTitle" placeholder="请输入售卖标题" clearable/>
</el-form-item>
	</el-col>
<el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="8">
	<el-form-item label="SKU图片" prop="skuPicUrl"><UploadImage
                v-if="dialog.add"
                action="actionUrl"
                formProp="skuPicUrl"
                :fileList="[]"
                @imgUploadSuccess="imgUploadSuccess"
                @imgRemoveSuccess="imgRemoveSuccess"
              />
</el-form-item>
	</el-col>
<el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="8">
	<el-form-item label="分销商级别" prop="distributionLevel">
	<el-input v-model="form.distributionLevel" placeholder="请输入分销商级别" clearable/>
</el-form-item>
	</el-col>
<el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="8">
	<el-form-item label="佣金比例" prop="commissionPercent">
	<el-input-number v-model="form.commissionPercent" placeholder="请输入佣金比例" clearable style="width: 100%;"/>
</el-form-item>
	</el-col>

        </el-row>
      </el-form>
      <div slot="footer">
        <el-button @click="dialog.add = false">取消</el-button>
        <el-button type="primary" @click="add" :loading="loading.add">添加</el-button>
      </div>
    </el-dialog>
    <el-dialog
      :visible.sync="dialog.edit"
      :close-on-click-modal="false"
      title="修改"
      width="80%"
      append-to-body
      @closed="dialogClosed('editForm')"
    >
      <el-form ref="editForm" :model="form" label-width="120px" :rules="validateRules">
        <el-row>
          <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="8">
	<el-form-item label="角色名称" prop="roleTitle"><el-input v-model="form.roleTitle" placeholder="请输入角色名称" disabled clearable />
              <el-button
                type="text"
                size="small"
                @click="showJoinSearch({
                searchDialog: 'RoleMain'
              })"
              >选择角色名称</el-button>
</el-form-item>
	</el-col>
<el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="8">
	<el-form-item label="商品标题" prop="goodsTitle"><el-input v-model="form.goodsTitle" placeholder="请输入商品标题" disabled clearable />
              <el-button
                type="text"
                size="small"
                @click="showJoinSearch({
                searchDialog: 'GoodsInfoMain'
              })"
              >选择商品标题</el-button>
</el-form-item>
	</el-col>
<el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="8">
	<el-form-item label="商品图片" prop="goodsPicUrl"><UploadImage
                v-if="dialog.edit"
                action="actionUrl"
                formProp="goodsPicUrl"
                :fileList="[{url: form.goodsPicUrl ? form.goodsPicUrl.indexOf('http') >= 0 ? form.goodsPicUrl: resUrl + form.goodsPicUrl: ''}]"
                @imgUploadSuccess="imgUploadSuccess"
                @imgRemoveSuccess="imgRemoveSuccess"
              />
</el-form-item>
	</el-col>
<el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24">
	<el-form-item label="售卖标题" prop="skuTitle">
	<el-input type="textarea" v-model="form.skuTitle" placeholder="请输入售卖标题" clearable/>
</el-form-item>
	</el-col>
<el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="8">
	<el-form-item label="SKU图片" prop="skuPicUrl"><UploadImage
                v-if="dialog.edit"
                action="actionUrl"
                formProp="skuPicUrl"
                :fileList="[{url: form.skuPicUrl ? form.skuPicUrl.indexOf('http') >= 0 ? form.skuPicUrl: resUrl + form.skuPicUrl: ''}]"
                @imgUploadSuccess="imgUploadSuccess"
                @imgRemoveSuccess="imgRemoveSuccess"
              />
</el-form-item>
	</el-col>
<el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="8">
	<el-form-item label="分销商级别" prop="distributionLevel">
	<el-input v-model="form.distributionLevel" placeholder="请输入分销商级别" clearable/>
</el-form-item>
	</el-col>
<el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="8">
	<el-form-item label="佣金比例" prop="commissionPercent">
	<el-input-number v-model="form.commissionPercent" placeholder="请输入佣金比例" clearable style="width: 100%;"/>
</el-form-item>
	</el-col>

        </el-row>
      </el-form>
      <div slot="footer">
        <el-button @click="dialog.edit = false">取消</el-button>
        <el-button type="primary" @click="edit" :loading="loading.edit">修改</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import * as utils from '@/utils/utils'
import * as ResponseStatus from '@/utils/response-status'
import UploadImage from '@/components/Upload/UploadImage'
import Tinymce from '@/components/Tinymce'
const resUrl = process.env.VUE_APP_RES_URL
export default {
  name: 'GoodsCommissionAddEdit',
  components: {
    UploadImage,
    Tinymce
  },
  data() {
    return {
      dialog: {
        add: false,
        edit: false
      },
      loading: {
        add: false,
        edit: false
      },
      form: {
        roleId: undefined,
roleTitle: undefined,
roleIsActive: undefined,
goodsId: undefined,
goodsTitle: undefined,
goodsIsActive: undefined,
goodsPicUrl: undefined,
goodsSkuId: undefined,
skuTitle: undefined,
skuPicUrl: undefined,
skuIsActive: undefined,
distributionLevel: undefined,
commissionPercent: undefined,

      },
      validateRules: {
        roleId: [
{type: 'integer', required: true, message: '此项为必须项', trigger: 'blur, change'}
],
roleTitle: [
{type: 'string', required: true, message: '此项为必须项', trigger: 'blur'},
{type: 'string', min: 1, max: 50, message: '必须1-50个字符', trigger: 'blur'}
],
roleIsActive: [
{type: 'integer', required: true, message: '此项为必须项', trigger: 'blur, change'}
],
goodsId: [
{type: 'integer', required: true, message: '此项为必须项', trigger: 'blur, change'}
],
goodsTitle: [
{type: 'string', required: true, message: '此项为必须项', trigger: 'blur'},
{type: 'string', min: 1, max: 100, message: '必须1-100个字符', trigger: 'blur'}
],
goodsIsActive: [
{type: 'integer', required: true, message: '此项为必须项', trigger: 'blur, change'}
],
goodsPicUrl: [
{type: 'string', required: true, message: '此项为必须项', trigger: 'blur'},
{type: 'string', min: 1, max: 500, message: '必须1-500个字符', trigger: 'blur'}
],
skuTitle: [
{type: 'string', min: 1, max: 255, message: '必须1-255个字符', trigger: 'blur'}
],
skuPicUrl: [
{type: 'string', min: 1, max: 500, message: '必须1-500个字符', trigger: 'blur'}
],
distributionLevel: [
{type: 'integer', required: true, message: '此项为必须项', trigger: 'blur, change'}
],
commissionPercent: [
{type: 'number', required: true, message: '此项为必须项', trigger: 'blur, change'}
],

      },
      dataDictCodes: ['YES_NO',],
      selects: {
        roleIsActiveSelect: [],
goodsIsActiveSelect: [],
skuIsActiveSelect: [],

      },
      resUrl: resUrl
    }
  },
  computed: {},
  mounted() {
    this.initDataDict()
    utils
      .getDataDict(this.dataDictCodes)
      .then(response => {
        if (response) {
          utils.getSelectDictItems({
            mainComponent: this,
            dataDictItems: response,
            dictCode: 'YES_NO',
            formProp: 'roleIsActive',
            dataProp: 'roleIsActiveSelect'
          })
utils.getSelectDictItems({
            mainComponent: this,
            dataDictItems: response,
            dictCode: 'YES_NO',
            formProp: 'goodsIsActive',
            dataProp: 'goodsIsActiveSelect'
          })
utils.getSelectDictItems({
            mainComponent: this,
            dataDictItems: response,
            dictCode: 'YES_NO',
            formProp: 'skuIsActive',
            dataProp: 'skuIsActiveSelect'
          })

        }
      })
      .catch(error => {})
  },
  methods: {
    initDataDict() {

    },
    dialogClosed(formRef) {
      this.$refs[formRef].resetFields()
      for (let key in this.form) {
        this.form[key] = undefined
      }
    },
    add() {
      this.$emit('add')
    },
    edit() {
      this.$emit('edit')
    },
    /** 触发父组件展示关联表数据的搜索对话框 */
    showJoinSearch(options) {
      this.$emit('showJoinSearchDialog', options)
    },
    imgUploadSuccess(formProp, url) {
      this.form[formProp] = url
    },
    imgRemoveSuccess(formProp) {
      this.form[formProp] = undefined
    }
  }
}
</script>

<style>
</style>